<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
              <j-multi-select-tag :options="options_channelApply" v-model="status_MultiString" placeholder="请选择审批状态"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('经销商可售物料模板.xlsx')">下载模板</a-button>
      <a-button type="primary" icon="import" @click="handleImport">价格导入</a-button>

    </div>

    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:type}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a v-has="'channel:updatePrice'" :hidden="[1,2].indexOf(record.status) === -1" @click="handleEditPrice(record)">修改价格</a>
          <a v-has="'channel:supplyChainApprove'" style="margin-left: 15px;" :hidden="[1].indexOf(record.status) === -1" @click="handleApprove(record,1)">供应链审核</a>
          <a v-has="'channel:financeApprove'" style="margin-left: 15px;" :hidden="[2].indexOf(record.status) === -1" @click="handleApprove(record,2)">财务审核</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <a-tabs>
      <a-tab-pane tab="申请明细">
      </a-tab-pane>
    </a-tabs>
    <!-- 表单区域 -->
    <financeApplyList ref="FinanceApplyList"></financeApplyList>
    <stmChannelProductApply-modal ref="modalForm" @ok="modalFormOk"></stmChannelProductApply-modal>
    <stm-channel-edit-product-price ref="StmChannelEditProductPrice"  @ok="modalFormOk"></stm-channel-edit-product-price>
    <ChannelProductApplyApproveModal ref="ChannelProductApplyApproveModal"  @ok="modalFormOk" ></ChannelProductApplyApproveModal>
    <StmChannelProductImport ref="StmChannelProductImport"  @ok="modalFormOk"></StmChannelProductImport>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import StmChannelProductApplyModal from './modules/StmChannelProductApplyModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import StmChannelProductApplyItemList from './StmChannelProductApplyItemList'
import StmChannelEditProductPrice from './modules/StmChannelEditProductPrice'
import FinanceApplyList from './StmChannelProductFinanceApplyList'
import ChannelProductApplyApproveModal from './modules/ChannelProductApplyApproveModal'
import JMultiSelectTag from '../../components/dict/JMultiSelectTag'
import {downFile} from "@api/manage";
import StmChannelProductImport from './modules/StmChannelProductImport'

export default {
  name: "StmChannelProductApplyList",
  mixins: [JeecgListMixin],
  components: {
    StmChannelProductApplyModal,
    StmChannelProductApplyItemList,
    StmChannelEditProductPrice,
    FinanceApplyList,
    ChannelProductApplyApproveModal,
    JMultiSelectTag,
    StmChannelProductImport
  },
  data() {
    return {
      description: '渠道产品申请表管理页面',
      status_MultiString:"",
      // 表头
      columns: [
        {
          title: '申请Id',
          align: "center",
          dataIndex: 'applyId'
        },
        {
          title: '渠道名称',
          align: "center",
          dataIndex: 'channelName'
        },
        {
          title: '申请状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '申请人名称',
          align: "center",
          dataIndex: 'userName'
        },
        {
          title: '申请时间',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      options_channelApply: [{
        label: " 供应链审核",
        value: "1"
      }, {
        label: "财务审核",
        value: "2"
      }, {
        label: "审核通过",
        value: "3"
      }, {
        label: "审核不通过",
        value: "4"
      }],
      type: "radio",
      url: {
        list: "/stm/stmChannelProductApply/list",
        delete: "/stm/stmChannelProductApply/delete",
        deleteBatch: "/stm/stmChannelProductApply/deleteBatch",
        exportXlsUrl: "stm/stmChannelProductApply/exportXls",
        exportXls: '/stm/stmStoreInfo/download'
      },
    }
  },
  computed: {
  },
  created() {
    this.queryParam.status_MultiString = ''
  },
  watch: {
    status_MultiString(v) {
      this.queryParam.status_MultiString = this.status_MultiString
    }
  },
  methods: {
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
      this.applyId = this.selectionRows[0].applyId;
      console.log(4444)
      // this.$refs.SupplyChainApplyList.getMain(this.selectionRows[0].applyId);
      this.$refs.FinanceApplyList.getMain(this.selectionRows[0].applyId);
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
    },
    handleEditPrice: function (record) {
      this.$refs.StmChannelEditProductPrice.getMain(record.applyId);
    },
    handleApprove(record,type){
      this.$refs.ChannelProductApplyApproveModal.show(type,record.applyId);
    },
    handleImport(){
      console.log(111)
      this.$refs.StmChannelProductImport.show();
    },
    onStatusChange: function (value) {
      this.queryParam.status_MultiString = value
    },
    handleExportXls(fileName) {
      downFile(this.url.exportXls, null).then((data) => {
        if (!data) {
          this.$message.warning("文件下载失败")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], {type: 'application/vnd.ms-excel'}), fileName)
        } else {
          let url = window.URL.createObjectURL(new Blob([data], {type: 'application/vnd.ms-excel'}))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName)
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>